<script type="text/javascript">
/*-----------------------------------------------------------------------------
Initialize
-----------------------------------------------------------------------------*/
$(document).ready(function() {
	// Tabs
	$('#tabs').tabs();
});

/*-----------------------------------------------------------------------------
Events
-----------------------------------------------------------------------------*/
$('#btn-save').click(function(){
    var tArray = new Array();
    var myChild;
    
    //--- collect images ---
    $('.imagePicker').each(function(){
        myChild = $(this).children('img')
        if ( myChild.length ) {
            tArray.push( myChild.attr('src') );
        }
    });
    $('#DProductShop_images').val( tArray.join(';') );
    //--- collect images ---
    
    $('#input-form').submit();
    return false;
});

$('.btn-cancel').click(function(){
    url = '<?php echo $this->createUrl('clearSession', array(
        'scenario' => $model->getScenario()
    )); ?>';
    $.post(url, '', function(){
        window.location = '<?php echo $this->createUrl('index'); ?>';
    });
})

$('#btn-refresh').click(function(){
    var url = '<?php echo $this->createUrl('clearState') ?>';
    $.post(url, '', function(){
        window.location = "<?php echo $this->createUrl('index'); ?>";
    });
})

$('#btn-reset').click(function(){
    window.location.reload();
})

$('#btn-search').click(function(){
    $('#search-box').toggleClass('hidden');
    $('#search-box').slideToggle();
})

$('#btn-submit').click(function(){
    url = '<?php echo $this->createUrl('index'); ?>' + '?' + $('#search-form').serialize();
    $.fn.yiiGridView.update('data-grid', {
        url: url
    });
})

$('.imagePickerWrapper .delete').live('click', function(){
    var imgObj = $(this).parent('p').prev('p').children('img');
    $(this).parent('p').prev('p').append('<span>' + imgObj.attr('alt') + '</span>');
    imgObj.remove();
    $(this).parent('p').remove();
    return false;
});

/*-----------------------------------------------------------------------------
Functions
-----------------------------------------------------------------------------*/
function updateGridview()
{
  $.fn.yiiGridView.update('data-grid');
}

function loadFrame(url, container, width, height, callBack, frameId, title) {
  var frameAttr = 'width="100%" height="100%"'
    + 'marginWidth="0" marginHeight="0"'
    + 'frameBorder="0"';
  
  myDialog = $(container).html('<iframe id="' + frameId + '" '+ frameAttr + '/>').dialog({
    modal: true,
    width: width, height: height,
    position: ['center', 55],
    draggable: false, resizable: false,
    bgiframe: true,
    close: callBack,
    title: title,
    zIndex: 10000
  });
  $("#" + frameId).attr("src", url);

  return myDialog;
};
</script>